package com.fulihui.information.core.redis;

import com.fulihui.information.common.config.AppConst;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Set;

/**
 * 热门内容分享数排序存储
 *
 * @author Willard Hu on 2017/1/11.
 */
@Component("redisHotsContentSharedTimesSortDB")
public class RedisHotsContentSharedTimesSortDB extends AbstractRedisContentSortDB {

    /**
     * 热门资讯按分享量排序列表存 Redis 的 Key
     */
    private static final String HOTS_CONTENT_ITEM_SHAREDTIMES_SORTED_KEY =
            "INFORMATION:CATEGORY_ITEM_DB:" + AppConst.CONTENT_HOTS_CATEGORY_CODE + "_SHAREDTIMES";

    @Override
    public long save(String contentId, double score, String categoryCode) {
        return doSave(HOTS_CONTENT_ITEM_SHAREDTIMES_SORTED_KEY, contentId, score);
    }

    @Override
    public long bathSave(Map<String, Double> params, String categoryCode) {
        return doBathSave(HOTS_CONTENT_ITEM_SHAREDTIMES_SORTED_KEY, params);
    }

    @Override
    public double incrScore(String contendId, double num, String categoryCode) {
        return doIncrScore(HOTS_CONTENT_ITEM_SHAREDTIMES_SORTED_KEY, contendId, num);
    }

    @Override
    public Set<String> range(int start, int end, String categoryCode) {
        return doRange(HOTS_CONTENT_ITEM_SHAREDTIMES_SORTED_KEY, start, end);
    }

    @Override
    public Set<String> rangeByScore(double min, double max, String categoryCode) {
        return doRangeByScore(HOTS_CONTENT_ITEM_SHAREDTIMES_SORTED_KEY, min, max);
    }

    @Override
    public long rangeByScoreCount(double min, double max, String categoryCode) {
        return doRangeByScoreCount(HOTS_CONTENT_ITEM_SHAREDTIMES_SORTED_KEY, min, max);
    }

    @Override
    public long size(String categoryCode) {
        return doSize(HOTS_CONTENT_ITEM_SHAREDTIMES_SORTED_KEY);
    }

    @Override
    public long remove(String categoryCode, String... ids) {
        return doRemove(HOTS_CONTENT_ITEM_SHAREDTIMES_SORTED_KEY, ids);
    }

    @Override
    public long removeRange(int start, int end, String categoryCode) {
        return doRemoveRange(HOTS_CONTENT_ITEM_SHAREDTIMES_SORTED_KEY, start, end);
    }
}
